<template>
  <!--单次使用核销-->
  <div style="padding-bottom: 60px">
    <div class="msg">
      <div class="weui-media-box weui-media-box_appmsg">
        <div class="weui-media-box__hd">
          <img :src="accountGoods.coverImg|imgPathFilter" alt="" class="weui-media-box__thumb" width="100" height="82">
        </div>
        <div class="weui-media-box__bd">
          <h4 class="weui-media-box__title">{{accountGoods.goodsName}}</h4>
          <p class="weui-media-box__desc">×{{accountGoods.goodsNum}}</p>
        </div>
      </div>
    </div>
    <p class="offer" @click="isVisible=true">使用验证</p>
    <div class="model" v-show="isVisible">
      <div class="bg"></div>
      <div class="modelContent">
        <img src="../../../assets/close.png" alt="" width="15" @click="isVisible=false">
        是否确定验证，验证后该码将  无法使用
        <p class="btn">
          <button @click="goCheck(accountGoods.accountGoodsId)">确定验证</button>
          <button @click="isVisible=false">取消验证</button>
        </p>
      </div>
    </div>
    <div class="model" v-show="isShowTip">
      <div class="bg"></div>
      <!--两种弹框不同内容-->
      <div class="modelContent">
        <img src="../../../assets/close.png" alt="" width="15" @click="isShowTip=false">
        {{tipMsg}}
        <p class="btn buzu">
          <button @click="isShowTip=false">确定</button>
        </p>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import {getAccountGoodsInfo, accountGoodsDanciUseCheck} from '../../../../test/unit/http'
  import {Toast} from 'we-vue'
  export default {
    name: 'danci',
    props: {},
    data() {
      return {
        isVisible: false,
        isShowTip: false,
        accountGoods: {},
        tipMsg: ''
      };
    },
    methods: {
      getData(params){
        getAccountGoodsInfo(params).then(res => {
          if (res.code === 100) {
            console.log(res);
            this.accountGoods = res.object;
          } else {
            Toast.fail(res.info);
          }
        })
      },
      goCheck(accountGoodsId){
        this.isVisible = false;
        accountGoodsDanciUseCheck({accountGoodsId: accountGoodsId}).then(res => {
          if (res.code == 100) {
            this.$router.push({path: 'success'})
          }
          else {
            this.isShowTip = true;
            this.tipMsg = res.info;
          }
        })
      }
    },
    created() {
      var accountGoodsId = this.$route.query.accountGoodsId;
      let params = {accountGoodsId: accountGoodsId};
      this.getData(params);
    },
    components: {}
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  .bg {
    background-color: rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 50px;
  }

  .model .modelContent {
    background-color: #fff;
    border-radius: 8px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin-left: -43%;
    margin-top: -111px;
    z-index: 2;
    padding: 40px 10px 20px;
    width: 80%;
    text-align: left;
    img {
      position: absolute;
      right: 10px;
      top: 10px
    }
    .btn {
      button {
        height: 42px;
        line-height: 42px;
        color: #fff;
        outline: none;
        border: none;
        width: calc(50% - 20px);
        border-radius: 8px;
        margin-top: 25px;
      }
      :last-child {
        background-color: #ccc;

      }
      :first-child {
        background-color: #f98e3c;
        margin-right: 20px;

      }
    }
    .buzu button {
      width: 100%;
      background-color: #f98e3c;

    }
  }

  .offer {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-color: #f98e3c;
    height: 50px;
    line-height: 50px;
    color: #fff;
    z-index: 999;
  }

  .msg {
    border-bottom: 1px solid #ddd;
  }

  .weui-media-box_appmsg .weui-media-box__hd {
    width: 100px;
    height: auto;
  }

  .weui-media-box_appmsg .weui-media-box__bd {
    text-align: left;
  }

  .weui-media-box__title {
    font-size: 15px;
    color: #666;
    margin-bottom: 25px;
  }

  .weui-media-box__desc {
    font-size: 15px;
    color: #666;
    text-align: right;
  }
</style>
